package com.jiazhong.servlet;

import com.alibaba.fastjson.JSON;
import com.jiazhong.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther:shuXin
 */
@WebServlet("/axiosServlet")
public class AxiosServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("你好");

        User user = new User();
        user.setName("zhangsan");

        //2.设置响应格式为JSON
        resp.setContentType("application/json;charset=utf-8");
        //3.转换为json的格式进行发送到前端
        resp.getWriter().write(JSON.toJSONString(user));

    }
}
